review changes, round 2 part b
authorNick Cameron <ncameron@mozilla.com>
Thu, 29 Dec 2016 23:19:34 +0000 (12:19 +1300)
committerNick Cameron <ncameron@mozilla.com>
Thu, 5 Jan 2017 02:58:58 +0000 (15:58 +1300)
Remove the ContinueBuild concept, be lenient about missing files in all cases, and undo the fingerprint changes (not an issue now we're not stopping the build early).

src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/mod.rs

index dde13d4c2a7ea5a03aae8f2fc9e4af6e41721b7c..812240908ca631c5d1e87d322c603b2cf5807d3d 100644 (file)
@@ -148,10 +148,15 @@ impl Fingerprint {
     fn update_local(&self) -> CargoResult<()> {
         match self.local {
             LocalFingerprint::MtimeBased(ref slot, ref path) => {
-                if let Ok(meta) = fs::metadata(path) {
-                    let mtime = FileTime::from_last_modification_time(&meta);
-                    *slot.0.lock().unwrap() = Some(mtime);
-                }
+                let meta = fs::metadata(path).chain_error(|| {
+                    internal(format!("failed to stat `{}`", path.display()))
+                })?;
+                let mtime = FileTime::from_last_modification_time(&meta);
+                *slot.0.lock().unwrap() = Some(mtime);
+                // if let Ok(meta) = fs::metadata(path) {
+                //     let mtime = FileTime::from_last_modification_time(&meta);
+                //     *slot.0.lock().unwrap() = Some(mtime);
+                // }
             }
             LocalFingerprint::Precalculated(..) => return Ok(())
         }
index 0862a296ccb30958dd33c331e183ccd255ec775f..adbdbedc3c098e0cf8b25bbfa002d2abfb0412eb 100644 (file)
@@ -62,9 +62,9 @@ pub trait Executor: Send + Sync + 'static {
     fn init(&self, _cx: &Context) {}
     /// If execution succeeds, the ContinueBuild value indicates whether Cargo
     /// should continue with the build process for this package.
-    fn exec(&self, cmd: ProcessBuilder, _id: &PackageId) -> Result<ContinueBuild, ProcessError> {
+    fn exec(&self, cmd: ProcessBuilder, _id: &PackageId) -> Result<(), ProcessError> {
         cmd.exec()?;
-        Ok(ContinueBuild::Continue)
+        Ok(())
     }
 
     fn exec_json(&self,
@@ -72,9 +72,9 @@ pub trait Executor: Send + Sync + 'static {
                  _id: &PackageId,
                  handle_stdout: &mut FnMut(&str) -> CargoResult<()>,
                  handle_srderr: &mut FnMut(&str) -> CargoResult<()>)
-                 -> Result<ContinueBuild, ProcessError> {
+                 -> Result<(), ProcessError> {
         cmd.exec_with_streaming(handle_stdout, handle_srderr)?;
-        Ok(ContinueBuild::Continue)        
+        Ok(())
     }
 }
 
@@ -85,12 +85,6 @@ pub struct DefaultExecutor;
 
 impl Executor for DefaultExecutor {}
 
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum ContinueBuild {
-    Continue,
-    Stop,
-}
-
 // Returns a mapping of the root package plus its immediate dependencies to
 // where the compiled libraries are all located.
 pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
@@ -258,7 +252,6 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
             rustc.arg("-Awarnings");
         }
     }
-    let has_custom_args = unit.profile.rustc_args.is_some();
 
     let filenames = cx.target_filenames(unit)?;
     let root = cx.out_dir(unit);
@@ -332,7 +325,7 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
         }
 
         state.running(&rustc);
-        let cont = if json_messages {
+        if json_messages {
             exec.exec_json(rustc, &package_id,
                 &mut |line| if !line.is_empty() {
                     Err(internal(&format!("compiler stdout is not empty: `{}`", line)))
@@ -360,36 +353,34 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
                 }
             ).chain_error(|| {
                 human(format!("Could not compile `{}`.", name))
-            })?
+            })?;
         } else {
             exec.exec(rustc, &package_id).chain_error(|| {
                 human(format!("Could not compile `{}`.", name))
-            })?
-        };
-
-        if cont == ContinueBuild::Continue {
-            if do_rename && real_name != crate_name {
-                let dst = &filenames[0].0;
-                let src = dst.with_file_name(dst.file_name().unwrap()
-                                                .to_str().unwrap()
-                                                .replace(&real_name, &crate_name));
-                if !has_custom_args || src.exists() {
-                    fs::rename(&src, &dst).chain_error(|| {
-                        internal(format!("could not rename crate {:?}", src))
-                    })?;
-                }
-            }
+            })?;
+        }
 
-            if !has_custom_args || fs::metadata(&rustc_dep_info_loc).is_ok() {
-                info!("Renaming dep_info {:?} to {:?}", rustc_dep_info_loc, dep_info_loc);
-                fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| {
-                    internal(format!("could not rename dep info: {:?}",
-                                  rustc_dep_info_loc))
+        if do_rename && real_name != crate_name {
+            let dst = &filenames[0].0;
+            let src = dst.with_file_name(dst.file_name().unwrap()
+                                            .to_str().unwrap()
+                                            .replace(&real_name, &crate_name));
+            if src.exists() {
+                fs::rename(&src, &dst).chain_error(|| {
+                    internal(format!("could not rename crate {:?}", src))
                 })?;
-                fingerprint::append_current_dir(&dep_info_loc, &cwd)?;
             }
         }
 
+        if fs::metadata(&rustc_dep_info_loc).is_ok() {
+            info!("Renaming dep_info {:?} to {:?}", rustc_dep_info_loc, dep_info_loc);
+            fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| {
+                internal(format!("could not rename dep info: {:?}",
+                              rustc_dep_info_loc))
+            })?;
+            fingerprint::append_current_dir(&dep_info_loc, &cwd)?;
+        }
+
         if json_messages {
             machine_message::emit(machine_message::Artifact {
                 package_id: &package_id,
index ecc15e81db5282feff9aa41bdd06bb89a4c60616..9ec74f393f495bfeef0d63fc2b97e4790eb076ad 100644 (file)
@@ -5,7 +5,7 @@ pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages};
 pub use self::cargo_rustc::{compile_targets, Compilation, Kind, Unit};
 pub use self::cargo_rustc::Context;
 pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
-pub use self::cargo_rustc::{Executor, DefaultExecutor, ContinueBuild};
+pub use self::cargo_rustc::{Executor, DefaultExecutor};
 pub use self::cargo_run::run;
 pub use self::cargo_install::{install, install_list, uninstall};
 pub use self::cargo_new::{new, init, NewOptions, VersionControl};